<template>
  <div class="right-aside">
    <!-- 热门标签模块 -->
    <div class="card">
      <h3 class="title">🔥 热门话题</h3>
      <ul class="topic-list">
        <li
          v-for="topic in hotTopics"
          :key="topic.topicId"
          class="topic-item"
          @click="goTopic(topic.topicId)"
        >
          <span class="topic-name">{{ topic.topicName }}</span>
        </li>
      </ul>
      <div v-if="hotTopics.length === 0" class="empty-tip">暂无热门话题</div>
    </div>

    <!-- 公告栏 -->
    <div class="card">
      <h3 class="title">公告</h3>
      <p class="notice">🚧 本平台正在测试阶段，内容不代表最终效果。</p>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { getTopTopic } from '@/apis/topic'

const router = useRouter()
const hotTopics = ref([])

// 获取热门话题
const fetchHotTopics = async () => {
  try {
    const res = await getTopTopic()
    if (res.code === '200') {
      hotTopics.value = res.data.slice(0, 3) // 确保最多3条
    }
  } catch (error) {
    console.error('获取热门话题失败:', error)
  }
}

// 跳转话题页
const goTopic = (topicId) => {
  router.push(`/home/topic/${topicId}`)
}

onMounted(() => {
  fetchHotTopics()
})
</script>

<style scoped>
.right-aside {
  width: 240px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-left: 1px solid #eee;
  background-color: #fafafa;
  height: 100vh;
  overflow-y: auto;
}

.card {
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 10px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  background: #f0f0f0;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
}

.notice {
  font-size: 13px;
  color: #666;
  line-height: 1.4;
}

.topic-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topic-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-radius: 6px;
  background: #f8f9fa;
  cursor: pointer;
  transition: all 0.2s;
}

.topic-item:hover {
  background: #e9ecef;
  transform: translateX(4px);
}

.topic-name {
  font-size: 14px;
  color: #333;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-tip {
  color: #999;
  font-size: 13px;
  text-align: center;
  padding: 8px 0;
}
</style>
